/*
 * @Author: weidewei
 * @Date: 2025-05-13 16:21:10
 * @LastEditors: weidewei
 * @LastEditTime: 2025-05-16 18:23:27
 * @Description:
 * @FilePath: \v2\src\main.js
 */
import Vue from "vue";
import App from "./App.vue";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css"; // 必须引入样式文件
import store from "./store";
import router from "./router";
import VueVirtualScroller from 'vue-virtual-scroller';
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
// 一定要引入，否则无法拦截请求
// import './mock';
import http from "@/http";
Vue.use(VueVirtualScroller);
Vue.use(ElementUI);
Vue.directive("copy", function (el, binding) {
  // 双击触发复制
  if (binding.modifiers.dblclick) {
    el.addEventListener("dblclick", () => handleClick(el.innerText));
    el.style.cursor = "copy";
  } else if (binding.modifiers.icon) {
    // 点击icon触发复制
    if (el.hasIcon) return;
    const iconElement = document.createElement("i");
    iconElement.setAttribute("class", "el-icon-document-copy");
    iconElement.setAttribute("style", "margin-left:5px");
    el.appendChild(iconElement);
    el.hasIcon = true;
    iconElement.addEventListener("click", () => handleClick(el.innerText));
    iconElement.style.cursor = "copy";
  } else {
    // 单击触发复制
    el.addEventListener("click", () => handleClick(el.innerText));
    el.style.cursor = "copy";
  }
});
function handleClick(text) {
  // 创建元素
  if (!document.getElementById("copyTarget")) {
    const copyTarget = document.createElement("input");
    copyTarget.setAttribute(
      "style",
      "position:fixed;top:0;left:0;opacity:0;z-index:-1000;"
    );
    copyTarget.setAttribute("id", "copyTarget");
    document.body.appendChild(copyTarget);
  }

  // 复制内容
  const input = document.getElementById("copyTarget");
  input.value = text;
  input.select();
  document.execCommand("copy");
  alert('复制成功')
}
Vue.prototype.$http = http;
Vue.config.productionTip = false;
// 全局事件总线
Vue.prototype.$eventBus = new Vue();
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
